<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background-color: red;
        }
    </style>
</head>
<body>

    <div id="box" class="box"></div>
</body>
<script>
    // window.setTimeout(fn,2000)
    // function fn() {
    //     alert('wahaha')
    // }

    // var tid = window.setTimeout("fn()",2000)
    // function fn() {
    //     alert('wahaha')
    // }
    // clearTimeOut(ret)

    var ret = setInterval(fn,500)
    function fn(){
        var box = document.getElementById('box')
        box.classList.toggle('box')
    }
    // clearInterval(ret)
</script>
</html>